package com.ruoyi.assets.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.assets.domain.AssetCategories;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.assets.domain.AssetFinancial;
import com.ruoyi.assets.service.IAssetFinancialService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 折旧Controller
 * 
 * @author 孙帆科
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/financial")
public class AssetFinancialController extends BaseController
{
    @Autowired
    private IAssetFinancialService assetFinancialService;

    /**
     * 查询折旧列表
     */
    @RequiresPermissions("assets:financial:list")
    @GetMapping("/list")
    public TableDataInfo list(AssetFinancial assetFinancial)
    {
        startPage();
        List<AssetFinancial> list = assetFinancialService.selectAssetFinancialList(assetFinancial);
        return getDataTable(list);
    }

    /**
     * 导出折旧列表
     */
    @RequiresPermissions("assets:financial:export")
    @Log(title = "折旧", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetFinancial assetFinancial)
    {
        List<AssetFinancial> list = assetFinancialService.selectAssetFinancialList(assetFinancial);
        ExcelUtil<AssetFinancial> util = new ExcelUtil<AssetFinancial>(AssetFinancial.class);
        util.exportExcel(response, list, "折旧数据");
    }

    /**
     * 获取折旧详细信息
     */
    @RequiresPermissions("assets:financial:query")
    @GetMapping(value = "/{financialId}")
    public AjaxResult getInfo(@PathVariable("financialId") Long financialId)
    {
        return success(assetFinancialService.selectAssetFinancialByFinancialId(financialId));
    }

    /**
     * 获取折旧详细信息
     */
//    @RequiresPermissions("assets:financial:query")
    @GetMapping(value = "/getFinancialCategoryInfo/{cateoriesId}")
    public AjaxResult getFinancialCategoryInfo(@PathVariable("cateoriesId") Long cateoriesId)
    {
        AssetFinancial assetCategories = assetFinancialService.selectByCateoriesId(cateoriesId);
        System.out.println("你好"+assetCategories);
        return success(assetCategories);
    }

    /**
     * 新增折旧
     */
    @RequiresPermissions("assets:financial:add")
    @Log(title = "折旧", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetFinancial assetFinancial)
    {
        return toAjax(assetFinancialService.insertAssetFinancial(assetFinancial));
    }

    /**
     * 修改折旧
     */
    @RequiresPermissions("assets:financial:edit")
    @Log(title = "折旧", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetFinancial assetFinancial)
    {
        return toAjax(assetFinancialService.updateAssetFinancial(assetFinancial));
    }

    /**
     * 删除折旧
     */
    @RequiresPermissions("assets:financial:remove")
    @Log(title = "折旧", businessType = BusinessType.DELETE)
	@DeleteMapping("/{financialIds}")
    public AjaxResult remove(@PathVariable Long[] financialIds)
    {
        return toAjax(assetFinancialService.deleteAssetFinancialByFinancialIds(financialIds));
    }
}
